package com.killer.order.controller;

import com.killer.order.service.ICartService;
import com.killer.common.entity.Result;
import com.killer.order.util.TokenUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author Killer
 * @title: CardController
 * @projectName shop-parent
 * @description: TODO
 * @date 2021/11/1 15:53
 */
@RestController
@RequestMapping("/cart")
public class CartController {

    @Autowired
    private ICartService cartService;

    @PostMapping("/add")
    public Result add(@RequestParam Long skuId, @RequestParam Integer num) {
        cartService.add(TokenUtil.getCurrentUserId(), skuId, num);
        return Result.success();
    }

    @GetMapping("/list")
    public Result list() {
        Map<String, Object> resultMap = cartService.list(TokenUtil.getCurrentUserId());
        return Result.success(resultMap);
    }

    @PostMapping("/delete")
    public Result delete(@RequestParam Long skuId) {
        cartService.delete(TokenUtil.getCurrentUserId(), skuId);
        return Result.success();
    }

    @PostMapping("/updateCheckedStatus")
    public Result updateCheckedStatus(@RequestParam Long skuId,@RequestParam Boolean checked){
        cartService.updateCheckedStatus(TokenUtil.getCurrentUserId(), skuId, checked);
        return Result.success();
    }

}
